package com.hy.controller;

import cn.hutool.db.PageResult;
import com.hy.AppHttpCodeEnum;
import com.hy.Result.ResponseResult;
import com.hy.pojo.healthvideo.HealthVideo;
import com.hy.service.HealthVideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/Healthvideo")
public class HealthVideoController {

    @Autowired
    private HealthVideoService healthVideoService;

    /**
     * 获取视频列表
     *
     * @param page     页码
     * @param pageSize 每页数量
     * @param title    视频标题
     * @param category 视频分类
     * @return 视频列表
     */
    @GetMapping("/list")
    public ResponseResult list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String title,
            @RequestParam(required = false) String category
    ) {
        try {
            PageResult<HealthVideo> result = healthVideoService.getVideoList(page, pageSize, title, category);
            return ResponseResult.okResult(result);
        } catch (Exception e) {
            log.error("获取视频列表失败", e);
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR.getCode(), "获取视频列表失败");
        }
    }

//    @GetMapping("/{id}")
//    public ResponseResult getDetail(@PathVariable Long id) {
//        try {
//            HealthVideo video = healthVideoService.getVideoById(id);
//            if (video == null) {
//                return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
//            }
//            return ResponseResult.okResult(video);
//        } catch (Exception e) {
//            log.error("获取视频详情失败", e);
//            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR.getCode(), "获取视频详情失败");
//        }
//    }
//
//    @PostMapping("/{id}/view")
//    public ResponseResult incrementViewCount(@PathVariable Long id) {
//        try {
//            healthVideoService.incrementViewCount(id);
//            return ResponseResult.okResult();
//        } catch (Exception e) {
//            log.error("更新播放次数失败", e);
//            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR.getCode(), "更新播放次数失败");
//        }
//    }
//
//    @PostMapping("/{id}/like")
//    public ResponseResult incrementLikeCount(@PathVariable Long id) {
//        try {
//            healthVideoService.incrementLikeCount(id);
//            return ResponseResult.okResult();
//        } catch (Exception e) {
//            log.error("更新点赞数失败", e);
//            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR.getCode(), "更新点赞数失败");
//        }
//    }
}